package cn.sail.shiroAuthenticator.main;

import cn.sail.shiroAuthenticator.security.CustomRealm;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.realm.text.IniRealm;
import org.apache.shiro.subject.Subject;

public class ShiroWithCustomRealmTest {
    public static void main(String[] args) {
        //创建安全管理器
        DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
        //自定义Realm进行用户校验
        CustomRealm customRealm = new CustomRealm();
        defaultSecurityManager.setRealm(customRealm);
        //安全管理器设置到运行环境仲
        SecurityUtils.setSecurityManager(defaultSecurityManager);
        //获取当前操作的主体
        Subject subject = SecurityUtils.getSubject();
        //创建token
        UsernamePasswordToken yxjToken = new UsernamePasswordToken("jerry", "123456");
        //传递token进行校验
        subject.login(yxjToken);
        //这里的校验是去shiro的内部进行校验
        System.out.println("用户的认证状态"+subject.isAuthenticated());

    }
}
